﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using JBeamLibrary.VehicleParts;
using JBeamLibrary.VehicleParts.Elements;

namespace DriveBeamEditor.Controls.BeamNG.Forms
{
    public partial class NodeSelectionForm : BeamNGForm
    {
        #region Fields

        private VehiclePart _vehiclePart;

        public event EventHandler VehiclePartChanged;

        #endregion

        #region Properties

        public VehiclePart VehiclePart
        {
            get { return _vehiclePart; }
            set
            {
                if (_vehiclePart == value) return;
                _vehiclePart = value;
                OnVehiclePartChanged();
            }
        }

        public Node SelectedNode
        {
            get { return nodesSource.Current as Node; }
        }

        #endregion

        #region CTORs

        public NodeSelectionForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Events

        private void xbOk_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            if (!Modal) Close();
        }

        private void xbCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            if (!Modal) Close();
        }

        private void listNodes_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        #endregion

        #region Methods

        private void BindNodes()
        {
            nodesSource.DataSource = VehiclePart.Nodes.Collection;
            nodesSource.ResetBindings(false);
        }

        private void OnVehiclePartChanged()
        {
            BindNodes();

            if (VehiclePartChanged != null)
                VehiclePartChanged(this, new EventArgs());
        }

        #endregion
    }
}
